package com.atguigu.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class DeadLockDemo {
    public static void main(String[] args) {
        Lock lock1 = new ReentrantLock();
        Lock lock2 = new ReentrantLock();


        new Thread(()->{
            lock1.lock();
            try {
                Thread.sleep(2000);
                lock2.lock();
                try {
                    System.out.println("000");
                }finally {
                    lock2.unlock();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } finally {
                lock1.unlock();
            }
        }).start();

        new Thread(()->{
            lock2.lock();
            try {
                Thread.sleep(2000);

                lock1.lock();
                try {
                    System.out.println("000");
                }finally {
                    lock1.unlock();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock2.unlock();
            }
        }).start();

        //jps  展示java线程
        // jstack + 线程ID 展示某一线程的具体情况
    }
}
